package com.ruoyi.web.controller.market.form;

import java.util.List;
import java.util.Map;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.db.domain.BaseTypeInfo;
import com.ruoyi.db.domain.MemberExtInfo;
import com.ruoyi.db.domain.MemberInfo;
import com.ruoyi.market.http.service.MarketApiService;
import com.ruoyi.member.service.IMemberInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.FormInfo;
import com.ruoyi.form.service.IFormInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.FormInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 表单推送信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-16
 */
@Controller
@RequestMapping("/form/info")
public class FormInfoController extends BaseController
{
    private String prefix = "form/info";

    @Autowired
    private IFormInfoService formInfoService;

    @RequiresPermissions("form:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询表单推送信息列表
     */
    @RequiresPermissions("form:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FormInfo formInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = formInfoService.selectFormInfoListMap(formInfo);
        mapList = new FormInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出表单推送信息列表
     */
    @RequiresPermissions("form:info:export")
    @Log(title = "表单推送信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FormInfo formInfo)
    {
        List<FormInfo> list = formInfoService.selectFormInfoList(formInfo);
        ExcelUtil<FormInfo> util = new ExcelUtil<FormInfo>(FormInfo.class);
        return util.exportExcel(list, "表单推送信息数据");
    }

    /**
     * 新增表单推送信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存表单推送信息
     */
    @RequiresPermissions("form:info:add")
    @Log(title = "表单推送信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FormInfo formInfo)
    {
        return toAjax(formInfoService.insertFormInfo(formInfo));
    }

    /**
     * 修改表单推送信息
     */
    @RequiresPermissions("form:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FormInfo formInfo = formInfoService.selectFormInfoById(id);
        mmap.put("formInfo", formInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存表单推送信息
     */
    @RequiresPermissions("form:info:edit")
    @Log(title = "表单推送信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FormInfo formInfo)
    {
        return toAjax(formInfoService.updateFormInfo(formInfo));
    }

    /**
     * 删除表单推送信息
     */
    @RequiresPermissions("form:info:remove")
    @Log(title = "表单推送信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(formInfoService.deleteFormInfoByIds(ids));
    }

    @RequiresPermissions("form:info:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(FormInfo formInfo)
    {
        return toAjax(formInfoService.updateFormInfo(formInfo));
    }



}
